/*
 * SelectScheduleTypeDialog.java
 *
 * Created on 6 de abril de 2009, 15:44
 */

package ubadbtools.deadlockAnalyzer.gui.forms;

import java.awt.Frame;
import java.util.Set;
import javax.swing.GroupLayout;
import javax.swing.JRadioButton;
import javax.swing.LayoutStyle;

import ubadbtools.deadlockAnalyzer.scheduleRecords.ScheduleRecord;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
@SuppressWarnings("serial")
public class EditRecordDialog extends javax.swing.JDialog {
    
	//[start] Atributos
	private ScheduleRecord record = null;
	private Set<String> transactions;
	private JRadioButton rbUnlock;
	private JRadioButton rbReqLock;
	private JRadioButton rbAbort;
	private Set<String> items;
	private Frame parent;
	//[end]
	
	//[start] Constructor
    public EditRecordDialog(java.awt.Frame parent, boolean modal, Set<String> transactions, Set<String> items)
    {
        super(parent, modal);
        initComponents();
        
        this.transactions = transactions;
        this.items = items;
        this.parent = parent;
    }
    //[end]
    
    //[start] showDialog
    public static ScheduleRecord showDialog(Frame parent, Set<String> transactions, Set<String> items)
    {
    	EditRecordDialog dialog = new EditRecordDialog(parent, true, transactions, items);
        dialog.setVisible(true);
        
        return dialog.record;
    }
    //[end]
    
    //[start] InitComponents (AUTO-GENERATED)
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rbgActionType = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        rbStart = new javax.swing.JRadioButton();
        rbLock = new javax.swing.JRadioButton();
        rbCommit = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        butCancelar = new javax.swing.JButton();
        butAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        rbgActionType.add(rbStart);
        rbStart.setSelected(true);
        rbStart.setText("Start"); // NOI18N
        rbStart.setName("rbStart"); // NOI18N

        rbgActionType.add(rbLock);
        rbLock.setText("Lock"); // NOI18N
        rbLock.setName("rbLock"); // NOI18N
        {
        	rbUnlock = new JRadioButton();
        	rbUnlock.setText("Unlock");
        	rbUnlock.setName("rbUnlock");
        	rbgActionType.add(rbUnlock);
        }

        rbgActionType.add(rbCommit);
        rbCommit.setText("Commit"); // NOI18N
        rbCommit.setName("rbCommit"); // NOI18N

        {
        	rbReqLock = new JRadioButton();
        	rbReqLock.setText("Request Lock");
        	rbReqLock.setName("rbReqLock");
        	rbgActionType.add(rbReqLock);
        }
        
        {
        	rbAbort = new JRadioButton();
        	rbAbort.setText("Abort");
        	rbAbort.setName("rbAbort");
        	rbgActionType.add(rbAbort);
        }
        
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup()
        	.addComponent(rbStart, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	.addComponent(rbReqLock, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, GroupLayout.PREFERRED_SIZE)
        	.addComponent(rbLock, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, Short.MAX_VALUE)
        	.addComponent(rbUnlock, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, GroupLayout.PREFERRED_SIZE)
        	.addComponent(rbCommit, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
        	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	.addComponent(rbAbort, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
         	.addContainerGap(13, 13));
        
        jPanel1Layout.setHorizontalGroup(jPanel1Layout.createSequentialGroup()
        	.addContainerGap()
        	.addGroup(jPanel1Layout.createParallelGroup()
        	    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
        	        .addComponent(rbStart, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addGap(0, 20, Short.MAX_VALUE))
        	    .addGroup(jPanel1Layout.createSequentialGroup()
        	        .addComponent(rbCommit, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addGap(0, 0, Short.MAX_VALUE))
        	      .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
        	        .addComponent(rbAbort, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addGap(0, 19, Short.MAX_VALUE))
        	    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
        	        .addComponent(rbLock, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addGap(0, 19, Short.MAX_VALUE))
        	     .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
        	        .addComponent(rbReqLock, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addGap(0, 19, Short.MAX_VALUE))
        	      .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
        	        .addComponent(rbUnlock, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addGap(0, 19, Short.MAX_VALUE)))
        	        	.addContainerGap());

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel2.setText("Tipo de registro"); // NOI18N

        butCancelar.setText("Cancelar"); // NOI18N
        butCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                butCancelarMouseClicked(evt);
            }
        });

        butAceptar.setText("Aceptar"); // NOI18N
        butAceptar.setName("jButton1"); // NOI18N
        butAceptar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                butAceptarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setVerticalGroup(layout.createSequentialGroup()
        	.addContainerGap(18,Short.MAX_VALUE)
        	.addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	
        	.addComponent(jPanel1, (GroupLayout.PREFERRED_SIZE), 150, (GroupLayout.PREFERRED_SIZE))
        	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	    .addComponent(butAceptar, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(butCancelar, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	.addContainerGap(23, 23));
        layout.setHorizontalGroup(layout.createSequentialGroup()
        	.addContainerGap(36, 36)
        	.addGroup(layout.createParallelGroup()
        	    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	        .addComponent(butAceptar, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	        .addComponent(butCancelar, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addGap(0, 0, Short.MAX_VALUE))
        	    .addGroup(layout.createSequentialGroup()
        	        .addGap(8)
        	        .addGroup(layout.createParallelGroup()
        	            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                .addGap(0, 0, Short.MAX_VALUE)
        	                .addComponent(jPanel1, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        	                .addGap(6))
        	            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                .addPreferredGap(jPanel1, jLabel2, LayoutStyle.ComponentPlacement.INDENT)
        	                .addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)))
        	        .addGap(17)))
        	.addContainerGap(46, 46));

        pack();
    }// </editor-fold>//GEN-END:initComponents
	//[end]
    
    //[start] Eventos
    private void butAceptarMouseClicked(java.awt.event.MouseEvent evt)
    {//GEN-FIRST:event_butAceptarMouseClicked

    	// Genero el registro de log segun los valores en los controles del dialogo
    	if(rbStart.isSelected())
    		record = StartRecordDialog.showDialog(parent, transactions);
    	else if(rbCommit.isSelected())
    		record = CommitRecordDialog.showDialog(parent, transactions);
    	else if(rbLock.isSelected())
    		record = LockRecordDialog.showDialog(parent, transactions,items);
    	else if(rbUnlock.isSelected())
    		record = UnlockRecordDialog.showDialog(parent, transactions,items);
    	else if(rbAbort.isSelected())
    		record = AbortRecordDialog.showDialog(parent, transactions);
    	else if(rbReqLock.isSelected())
    		record = RequestLockRecordDialog.showDialog(parent, transactions,items);
    	
    	this.setVisible(false);
    }//GEN-LAST:event_butAceptarMouseClicked

    private void butCancelarMouseClicked(java.awt.event.MouseEvent evt)
    {//GEN-FIRST:event_butCancelarMouseClicked
        this.setVisible(false);
    }//GEN-LAST:event_butCancelarMouseClicked
    //[end]

    //[start] Variables Form (AUTO-GENERATED)
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butAceptar;
    private javax.swing.JButton butCancelar;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton rbCommit;
    private javax.swing.JRadioButton rbStart;
    private javax.swing.JRadioButton rbLock;
    private javax.swing.ButtonGroup rbgActionType;
    // End of variables declaration//GEN-END:variables
    //[end]
}

